package day_2022_9_to_12.Day;

/**
 * @author haomin
 * @date 2022/09/08 11:45
 **/
public class Day6_5_Num125_IsPalindrome {
    class Solution {
        public boolean isPalindrome(String s) {
            StringBuffer sb = new StringBuffer();
            for(int i = 0; i < s.length(); ++i){
                char c = s.charAt(i);
                if(Character.isLetter(c) || Character.isDigit(c))
                    sb.append(c);
            }
            return isReverse(sb.toString().toLowerCase());
        }
        private boolean isReverse(String str){
            int l = 0, r = str.length()-1;
            while(l <= r){
                if(str.charAt(l) != str.charAt(r)) return false;
                l++; r--;
            }
            return true;
        }
    }
}